package com.csjbot.snowbotagingtest;

import android.app.Activity;
import android.os.Bundle;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;


/**
 * @author: jl
 * @Time: 2017/1/6
 * @Desc:
 */

public class VideoPlay extends Activity {
    private JCVideoPlayerStandard jcVideoPlayerStandard;
    private String url;
    private String title;
    private boolean loop;
    protected int mCurrentState = -1;//-1相当于null
    protected static final int CURRENT_STATE_NORMAL = 0;
    protected static final int CURRENT_STATE_PREPAREING = 1;
    protected static final int CURRENT_STATE_PLAYING = 2;
    protected static final int CURRENT_STATE_PLAYING_BUFFERING_START = 3;
    protected static final int CURRENT_STATE_PAUSE = 5;
    protected static final int CURRENT_STATE_AUTO_COMPLETE = 6;
    protected static final int CURRENT_STATE_ERROR = 7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_video_play);
        init();
    }

    private void init() {
        jcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.videoView);
        Bundle bundle;
        if (null != getIntent().getBundleExtra("VIDEODATA")) {
            bundle = getIntent().getBundleExtra("VIDEODATA");
            url =  bundle.getString("url");
            title = bundle.getString("title");
            loop = bundle.getBoolean("loop",false);
            jcVideoPlayerStandard.setUp(url, title);
            jcVideoPlayerStandard.setLoop(loop);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        switch (mCurrentState) {
            case CURRENT_STATE_PAUSE:
            case CURRENT_STATE_AUTO_COMPLETE:
                break;
            default:
                jcVideoPlayerStandard.startButton.performClick();
                break;
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        this.mCurrentState = jcVideoPlayerStandard.getPlayStatus();
        if (null!=jcVideoPlayerStandard&&null!=jcVideoPlayerStandard.startButton&&mCurrentState == CURRENT_STATE_PLAYING) {
            jcVideoPlayerStandard.startButton.performClick();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
